import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useChatStore = defineStore(
  'chat',
  () => {
    const models = ref([
      { id: 1, name: 'deepseek-v3', icon: 'deepseek-logo', description: '更流畅', selected: true },
      {
        id: 2,
        name: 'deepseek-r1',
        icon: 'deepseek-logo',
        description: '深度思考',
        selected: false,
      },
    ])

    // 默认选中的模型
    const selectedModel = ref(models.value[0])
    // 默认是否联网搜索
    const isNetWork = ref(false)

    // 更新选中模型
    function updateSelectedModel(model) {
      // 将所有模型的选中状态置为false
      models.value.forEach((m) => {
        m.selected = false
      })

      // 选中模型的selected状态置为true
      model.selected = true

      // 更新选中模型
      selectedModel.value = model
    }

    // 更新联网搜索状态
    function updateNetStatus(status: boolean) {
      isNetWork.value = status
    }

    return {
      models,
      selectedModel,
      isNetWork,
      updateSelectedModel,
      updateNetStatus,
    }
  },
  {
    // 开启持久化
    persist: true,
  },
)
